<!DOCTYPE html>
<html lang="zh-Hans">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="zhengweiMao" />


    
    


<meta name="description" content="你好！我的世界">
<meta property="og:type" content="website">
<meta property="og:title" content="花神">
<meta property="og:url" content="https://maozw.gitee.io/maoge-blog/page/7/index.html">
<meta property="og:site_name" content="花神">
<meta property="og:description" content="你好！我的世界">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="花神">
<meta name="twitter:description" content="你好！我的世界">

<link rel="apple-touch-icon" href= "/apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="花神" type="application/atom+xml">



    <link rel="shortcut icon" href="/favicon.png">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/maoge-blog/css/style.css">


    <style> .article { opacity: 0;} </style>


<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>花神</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: true,
        isPost: false,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: true
    }
</script>


    <script>
        yiliaConfig.jquery_ui = [true, "//cdn.bootcss.com/jqueryui/1.10.4/jquery-ui.min.js", "//cdn.bootcss.com/jqueryui/1.10.4/css/jquery-ui.min.css"];
    </script>



    <script> yiliaConfig.rootUrl = "\/";</script>






</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/maoge-blog/" class="profilepic">
            <img src="img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/maoge-blog/">zhengweiMao</a></h1>
        </hgroup>

        

        
            <form id="search-form">
            <input type="text" id="local-search-input" name="q" placeholder="search..." class="search form-control" autocomplete="off" autocorrect="off" searchonload="" />
            <i class="fa fa-times" onclick="resetSearch()"></i>
            </form>
            <div id="local-search-result"></div>
            <p class='no-result'>No results found <i class='fa fa-spinner fa-pulse'></i></p>
        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/maoge-blog/">主页</a></li>
                        
                            <li><a href="/maoge-blog/archives/">所有文章</a></li>
                        
                            <li><a href="/maoge-blog/tags/">标签云</a></li>
                        
                            <li><a href="/maoge-blog/categories/">分类</a></li>
                        
                            <li><a href="/maoge-blog/about/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="mailto:123@123.com" title="Email"></a>
                            
                                <a class="fa GitHub" href="#" title="GitHub"></a>
                            
                                <a class="fa RSS" href="/maoge-blog/atom.xml" title="RSS"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于前端</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">zhengweiMao</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/maoge-blog/" class="profilepic">
                <img src="img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/maoge-blog/" title="回到主页">zhengweiMao</a></h1>
            </hgroup>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/maoge-blog/">主页</a></li>
                
                    <li><a href="/maoge-blog/archives/">所有文章</a></li>
                
                    <li><a href="/maoge-blog/tags/">标签云</a></li>
                
                    <li><a href="/maoge-blog/categories/">分类</a></li>
                
                    <li><a href="/maoge-blog/about/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="mailto:123@123.com" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="#" title="GitHub"></a>
                            
                                <a class="fa RSS" target="_blank" href="/maoge-blog/atom.xml" title="RSS"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap">
  
    <article id="post-花神(maoge)/5.分布式--zookeeper/1.zookeeper--简介" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/maoge-blog/2018/04/05/花神(maoge)/5.分布式--zookeeper/1.zookeeper--简介/" class="article-date">
      <time datetime="2018-04-05T04:04:22.000Z" itemprop="datePublished">2018-04-05</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/maoge-blog/2018/04/05/花神(maoge)/5.分布式--zookeeper/1.zookeeper--简介/">1.分布式--zookeeper--zookeeper简介</a>
    </h1>
  

      </header>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="1-分布式–zookeeper–zookeeper简介"><a href="#1-分布式–zookeeper–zookeeper简介" class="headerlink" title="1.分布式–zookeeper–zookeeper简介"></a>1.分布式–zookeeper–zookeeper简介</h3><p>简述</p>
<ul>
<li>ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications.<br>Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable.<br>Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage.<br>Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.</li>
<li>ZooKeeper是一个集中式服务，用于维护配置信息，命名，提供分布式同步和提供组服务。所有这些类型的服务以分布式应用程序的某种形式或另一种形式使用。<br>每次他们被实现，有很多工作，以修复错误和竞争条件是不可避免的。<br>由于实现这些服务的难度，应用程序最初通常嘲弄它们，这使得它们在变化的存在下变得脆弱并且难以管理。<br>即使正确地完成，这些服务的不同实施导致在应用被部署时的管理复杂性。</li>
</ul>
<p>-zookeeper简介<br></p>
<ol start="2">
<li>；传统的BIO 模式；</li>
</ol>
<h4 id="Zookeeper简介"><a href="#Zookeeper简介" class="headerlink" title="Zookeeper简介"></a>Zookeeper简介</h4><ul>
<li>Zookeeper是一个高效的分布式协调服务，可以提供配置信息管理、命名、分布式同步、集群管理、数据库切换等服务。<br>它不适合用来存储大量信息，可以用来存储一些配置、发布与订阅等少量信息。<br>Hadoop、Storm、消息中间件、RPC服务框架、分布式数据库同步系统，这些都是Zookeeper的应用场景。</li>
<li>Zookeeper集群中节点个数一般为奇数个（&gt;=3），若集群中Master挂掉，剩余节点个数在半数以上时，就可以推举新的主节点，继续对外提供服务。</li>
<li>Zookeeper使用的数据结构为树形结构，根节点为”/“。Zookeeper集群中的节点，根据其身份特性分为leader、follower、observer。leader负责客户端writer类型的请求；<br>follower负责客户端reader类型的请求，并参与leader选举；observer是特殊的follower，可以接收客户端reader请求，但是不会参与选举，可以用来扩容系统支撑能力，提高读取速度。</li>
<li>Zookeeper是一个基于观察者模式设计的分布式服务管理框架，负责存储和管理相关数据，接收观察者的注册。<br>一旦这些数据的状态发生变化，zookeeper就负责通知那些已经在zookeeper集群进行注册并关心这些状态发生变化的观察者，以便观察者执行相关操作。</li>
<li>Zookeeper使用的是ZAB原子消息广播协议，节点之间的一致性算法为Paxos，能够保障分布式环境中数据的一致性。<br>分布式场景下高可用是Zookeeper的特性，可以采用第三方客户端的实现，即Curator框架。</li>
</ul>
<h4 id="zookeeper特性"><a href="#zookeeper特性" class="headerlink" title="zookeeper特性"></a>zookeeper特性</h4><h5 id="8195-8195-特性-1-概念"><a href="#8195-8195-特性-1-概念" class="headerlink" title="&#8195;&#8195; 特性 1 概念"></a>&#8195;&#8195; 特性 1 概念</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">zookeeper是一个分布式协调服务：</span><br><span class="line">  a:zookeeper是为别的分布式程序服务的</span><br><span class="line">  b:zookeeper本身就是一个分布式程序（只要半数以上节点存活，zookeeper就能正常服务。）</span><br><span class="line">  c:zookeeper的服务范围：主从协调、服务器节点动态上下线、统一配置管理、分布式共享锁、统一名称服务...=</span><br><span class="line">  d:zookeeper底层其实只提供了两个功能：</span><br><span class="line">　　　（1）管理（存储、读取）用户程序提交的数据</span><br><span class="line">　　　（2）为用户程序提交数据节点监听服务</span><br></pre></td></tr></table></figure>
<h5 id="8195-8195-特性-2-集群机制"><a href="#8195-8195-特性-2-集群机制" class="headerlink" title="&#8195;&#8195; 特性 2 集群机制"></a>&#8195;&#8195; 特性 2 集群机制</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">半数机制：集群中半数以上机器存活，集群可用。</span><br><span class="line">zookeeper集群适合搭建在奇数台机器上。</span><br></pre></td></tr></table></figure>
<h5 id="8195-8195-特性-3-集群特点"><a href="#8195-8195-特性-3-集群特点" class="headerlink" title="&#8195;&#8195; 特性 3 集群特点"></a>&#8195;&#8195; 特性 3 集群特点</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Zookeeper：一个leader，多个follower组成的集群</span><br><span class="line">全局数据一致：每个server保存一份相同的数据副本，client无论连接到哪个server，数据都是一致的</span><br><span class="line">分布式读写，更新请求转发，由leader实施</span><br><span class="line">更新请求顺序进行，来自同一个client的更新请求按其发送顺序依次执行</span><br><span class="line">数据更新原子性，一次数据更新要么成功，要么失败</span><br><span class="line">实时性，在一定时间范围内，client能读到最新数据</span><br></pre></td></tr></table></figure>
<h5 id="8195-8195-特性-4-数据结构特点"><a href="#8195-8195-特性-4-数据结构特点" class="headerlink" title="&#8195;&#8195; 特性 4 数据结构特点"></a>&#8195;&#8195; 特性 4 数据结构特点</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">层次化的目录结构，命名符合常规文件系统规范</span><br><span class="line">每个节点在zookeeper中叫做Znode,并且其有一个唯一的路径标识</span><br><span class="line">节点Znode可以包含数据和子节点（但是EPHEMERAL类型的节点不能有子节点）</span><br><span class="line">客户端应用可以在节点上设置监视器</span><br><span class="line">节点类型：</span><br><span class="line">　　　1、Znode有两种类型：</span><br><span class="line">　　　　　 短暂（ephemeral）（断开连接自己删除）</span><br><span class="line">　　　　　 持久（persistent）（断开连接不删除）</span><br><span class="line">　　　2、Znode有四种形式的目录节点（默认是persistent ）</span><br><span class="line">　　　　　 PERSISTENT</span><br><span class="line">        PERSISTENT_SEQUENTIAL（持久序列/test0000000019 ）</span><br><span class="line">        EPHEMERAL</span><br><span class="line">        EPHEMERAL_SEQUENTIAL</span><br><span class="line">    3、创建znode时设置顺序标识，znode名称后会附加一个值，顺序号是一个单调递增的计数器，由父节点维护</span><br><span class="line">    4、在分布式系统中，顺序号可以被用于为所有的事件进行全局排序，这样客户端可以通过顺序号推断事件的顺序</span><br></pre></td></tr></table></figure>
<h5 id="8195-8195-特性-5-原理及内部选举机制"><a href="#8195-8195-特性-5-原理及内部选举机制" class="headerlink" title="&#8195;&#8195; 特性 5 原理及内部选举机制"></a>&#8195;&#8195; 特性 5 原理及内部选举机制</h5><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">原理：zookeeper在配置文件中并没有指定master和slave，但是，zookeeper在工作时，只有一个节点为leader，其余节点为follower，leader是通过内部的选举机制临时产生的。</span><br><span class="line"> 选举机制：（两种情况）</span><br><span class="line">（1）全新集群paxos</span><br><span class="line">  假设有五台服务器组成的zookeeper集群,它们的id从1-5,同时它们都是最新启动的,也就是没有历史数据,在存放数据量这一点上,都是一样的.假设这些服务器依序启动,来看看会发生什么.</span><br><span class="line">　　1) 服务器1启动,此时只有它一台服务器启动了,它发出去的报没有任何响应,所以它的选举状态一直是LOOKING状态</span><br><span class="line">　　2) 服务器2启动,它与最开始启动的服务器1进行通信,互相交换自己的选举结果,由于两者都没有历史数据,所以id值较大的服务器2胜出,但是由于没有达到超过半数以上的服务器都同意选举它(这个例子中的半数以上是3),所以服务器1,2还是继续保持LOOKING状态.</span><br><span class="line">　　3) 服务器3启动,根据前面的理论分析,服务器3成为服务器1,2,3中的老大,而与上面不同的是,此时有三台服务器选举了它,所以它成为了这次选举的leader.</span><br><span class="line">　　4) 服务器4启动,根据前面的分析,理论上服务器4应该是服务器1,2,3,4中最大的,但是由于前面已经有半数以上的服务器选举了服务器3,所以它只能接收当小弟的命了.</span><br><span class="line">　　5) 服务器5启动,同4一样,当小弟.</span><br><span class="line">（2）非全新集群（数据恢复）</span><br><span class="line">初始化的时候，是按照上述的说明进行选举的，但是当zookeeper运行了一段时间之后，有机器down掉，重新选举时，选举过程就相对复杂了。</span><br><span class="line">需要加入数据id、leader id和逻辑时钟。</span><br><span class="line">　　数据id：数据新的id就大，数据每次更新都会更新id。</span><br><span class="line">　　Leader id：就是我们配置的myid中的值，每个机器一个。</span><br><span class="line">　　逻辑时钟：这个值从0开始递增,每次选举对应一个值,也就是说:  如果在同一次选举中,那么这个值应该是一致的 ;  逻辑时钟值越大,说明这一次选举leader的进程更新.</span><br><span class="line">选举的标准就变成：</span><br><span class="line">　　1、逻辑时钟小的选举结果被忽略，重新投票</span><br><span class="line">　　2、统一逻辑时钟后，数据id大的胜出</span><br><span class="line">　　3、数据id相同的情况下，leader id大的胜出</span><br><span class="line">根据这个规则选出leader。</span><br></pre></td></tr></table></figure>

      
    </div>
    
    <div class="article-info article-info-index">
      
      
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/maoge-blog/categories/zookeeper/">zookeeper</a>
    </div>


      
      
      <div class="clearfix"></div>
    </div>
    
  </div>
  
</article>









  
    <article id="post-花神(maoge)/4.JVM相关/1.jvm虚拟机组成部分" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/maoge-blog/2018/02/05/花神(maoge)/4.JVM相关/1.jvm虚拟机组成部分/" class="article-date">
      <time datetime="2018-02-05T04:03:22.000Z" itemprop="datePublished">2018-02-05</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/maoge-blog/2018/02/05/花神(maoge)/4.JVM相关/1.jvm虚拟机组成部分/">1.jvm虚拟机组成部分</a>
    </h1>
  

      </header>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="1-jvm虚拟机组成部分"><a href="#1-jvm虚拟机组成部分" class="headerlink" title="1.jvm虚拟机组成部分"></a>1.jvm虚拟机组成部分</h3><h5 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h5><hr>
<ol>
<li>：jvm虚拟机组成部分</li>
</ol>
<hr>
<h4 id="（一）JVM的基本结构及其各部分详解"><a href="#（一）JVM的基本结构及其各部分详解" class="headerlink" title="（一）JVM的基本结构及其各部分详解"></a>（一）JVM的基本结构及其各部分详解</h4><h5 id="java虚拟机的基本结构如图："><a href="#java虚拟机的基本结构如图：" class="headerlink" title="java虚拟机的基本结构如图："></a>java虚拟机的基本结构如图：</h5><p>﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍<br>︴                       java虚拟机的基本结构<br>︴                                           ︴<br>︴    ﹍﹍﹍﹍﹍﹍﹍﹍<br>︴    ︴类加载子系统  ︴<br>︴    ﹍﹍﹍﹍﹍﹍﹍﹍<br>︴<br>︴<br>︴    ﹍﹍﹍﹍﹍﹍﹍﹍     ﹍﹍﹍﹍﹍﹍﹍﹍     ﹍﹍﹍﹍﹍﹍﹍﹍    ﹍﹍﹍﹍﹍﹍﹍﹍<br>︴    ︴类加载子系统  ︴   ︴JAVA堆       ︴   ︴直接内存     ︴   ︴本地方发栈   ︴<br>︴    ﹍﹍﹍﹍﹍﹍﹍﹍     ﹍﹍﹍﹍﹍﹍﹍﹍     ﹍﹍﹍﹍﹍﹍﹍﹍    ﹍﹍﹍﹍﹍﹍﹍﹍<br>︴<br>︴<br>︴       ﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍                  ﹍﹍﹍﹍﹍﹍<br>︴       ︴                                 ︴                 ︴          ︴<br>︴       ︴              垃圾回收系统        ︴                 ︴PC寄存器   ︴<br>︴       ﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍                  ﹍﹍﹍﹍﹍﹍<br>︴<br>︴﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍</p>
<p>&#8195;&#8195;1）类加载子系统负责从文件系统或者网络中加载Class信息，加载的类信息存放于一块称为方法区的内存空间。除了类的信息外，方法区中可能还会存放运行时常量池信息，包括字符串字面量和数字常量（这部分常量信息是Class文件中常量池部分的内存映射）。<br>&#8195;&#8195;2）java堆在虚拟机启动的时候建立，它是java程序最主要的内存工作区域。几乎所有的java对象实例都存放在java堆中。堆空间是所有线程共享的，这是一块与java应用密切相关的内存空间。<br>&#8195;&#8195;3）java的NIO库允许java程序使用直接内存。直接内存是在java堆外的、直接向系统申请的内存空间。通常访问直接内存的速度会优于java堆。因此出于性能的考虑，读写频繁的场合可能会考虑使用直接内存。由于直接内存在java堆外，因此它的大小不会直接受限于Xmx指定的最大堆大小，但是系统内存是有限的，java堆和直接内存的总和依然受限于操作系统能给出的最大内存。<br>&#8195;&#8195;4）垃圾回收系统是java虚拟机的重要组成部分，垃圾回收器可以对方法区、java堆和直接内存进行回收。其中，java堆是垃圾收集器的工作重点。和C/C++不同，java中所有的对象空间释放都是隐式的，也就是说，java中没有类似free()或者delete()这样的函数释放指定的内存区域。对于不再使用的垃圾对象，垃圾回收系统会在后台默默工作，默默查找、标识并释放垃圾对象，完成包括java堆、方法区和直接内存中的全自动化管理。<br>&#8195;&#8195;5）每一个java虚拟机线程都有一个私有的java栈，一个线程的java栈在线程创建的时候被创建，java栈中保存着帧信息，java栈中保存着局部变量、方法参数，同时和java方法的调用、返回密切相关。<br>&#8195;&#8195;6）本地方法栈和java栈非常类似，最大的不同在于java栈用于方法的调用，而本地方法栈则用于本地方法的调用，作为对java虚拟机的重要扩展，java虚拟机允许java直接调用本地方法（通常使用C编写）<br>&#8195;&#8195;7）PC（Program Counter）寄存器也是每一个线程私有的空间，java虚拟机会为每一个java线程创建PC寄存器。在任意时刻，一个java线程总是在执行一个方法，这个正在被执行的方法称为当前方法。如果当前方法不是本地方法，PC寄存器就会指向当前正在被执行的指令。如果当前方法是本地方法，那么PC寄存器的值就是undefined<br>&#8195;&#8195;8)执行引擎是java虚拟机的最核心组件之一，它负责执行虚拟机的字节码，现代虚拟机为了提高执行效率，会使用即时编译技术将方法编译成机器码后再执行。</p>
<h5 id="java堆"><a href="#java堆" class="headerlink" title="java堆"></a>java堆</h5><p>java堆是和应用程序关系最为密切的内存空间，几乎所有的对象都存放在堆上。并且java堆是完全自动化管理的，通过垃圾回收机制，垃圾对象会被自动清理，而不需要显示的释放。<br>根据java回收机制的不同，java堆有可能拥有不同的结构。最为常见的一种构成是将整个java堆分为新生代和老年代。其中新生代存放新生对象或者年龄不大的对象，老年代则存放老年对象。新生代有可能分为eden区、s0区、s1区，s0区和s1区也被称为from和to区，他们是两块大小相同、可以互换角色的内存空间。<br>在绝大多数情况下，对象首先分配在eden区，在一次新生代回收之后，如果对象还存活，则进入s0或者s1，每经过一次新生代回收，对象如果存活，它的年龄就会加1。当对象的年龄达到一定条件后，就会被认为是老年对象，从而进入老年代。其具体的垃圾回收算法在后面会介绍<br>示例：<br>该代码声明了一个类，并在main函数中创建了两个SimpleHeap实例。此时，各对象和局部变量的存放情况如图：<br>SimpleHeap实例本身分配在堆中，描述SimpleHeap类的信息存放在方法区，main函数中的s1 s2局部变量存放在java栈上，并指向堆中两个实例。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.jvm;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SimpleHeap</span> </span>&#123;</span><br><span class="line">　　<span class="keyword">private</span> <span class="keyword">int</span> id;</span><br><span class="line">　　<span class="function"><span class="keyword">public</span> <span class="title">SimpleHeap</span><span class="params">(<span class="keyword">int</span> id)</span></span>&#123;</span><br><span class="line">　　　　<span class="keyword">this</span>.id = id;</span><br><span class="line">　　&#125;</span><br><span class="line">　　<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">show</span><span class="params">()</span></span>&#123;</span><br><span class="line">　　　　System.out.println(<span class="string">"My id is "</span>+id);</span><br><span class="line">　　&#125;</span><br><span class="line"></span><br><span class="line">　　<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">　　　　SimpleHeap s1 = <span class="keyword">new</span> SimpleHeap(<span class="number">1</span>);</span><br><span class="line">　　　　SimpleHeap s2 = <span class="keyword">new</span> SimpleHeap(<span class="number">2</span>);</span><br><span class="line">　　　　s1.show();</span><br><span class="line">　　　　s2.show();</span><br><span class="line">　　&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h5 id="java栈"><a href="#java栈" class="headerlink" title="java栈"></a>java栈</h5><p>java栈是一块线程私有的内存空间。如果说，java堆和程序数据密切相关，那么java栈就是和线程执行密切相关。线程执行的基本行为是函数调用，每次函数调用的数据都是通过java栈传递的。</p>
<p>java栈与数据结构上的栈有着类似的含义，它是一块先进后出的数据结构，只支持出栈和进栈两种操作，在java栈中保存的主要内容为栈帧。每一次函数调用，都会有一个对应的栈帧被压入java栈，每一个函数调用结束，都会有一个栈帧被弹出java栈。如下图：栈帧和函数调用。函数1对应栈帧1，函数2对应栈帧2，依次类推。函数1中调用函数2，函数2中调用函数3，函数3调用函数4.当函数1被调用时，栈帧1入栈，当函数2调用时，栈帧2入栈，当函数3被调用时，栈帧3入栈，当函数4被调用时，栈帧4入栈。当前正在执行的函数所对应的帧就是当前帧（位于栈顶），它保存着当前函数的局部变量、中间计算结果等数据。</p>
<p>当函数返回时，栈帧从java栈中被弹出，java方法区有两种返回函数的方式，一种是正常的函数返回，使用return指令，另一种是抛出异常。不管使用哪种方式，都会导致栈帧被弹出。</p>
<p>在一个栈帧中，至少包含局部变量表、操作数栈和帧数据区几个部分。</p>
<p>原文地址：<a href="https://www.cnblogs.com/zwbg/p/6194470.html" target="_blank" rel="noopener">https://www.cnblogs.com/zwbg/p/6194470.html</a></p>

      
    </div>
    
    <div class="article-info article-info-index">
      
      
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/maoge-blog/categories/JVM相关/">JVM相关</a>
    </div>


      
      
      <div class="clearfix"></div>
    </div>
    
  </div>
  
</article>









  
    <article id="post-花神(maoge)/3.缓存-中间件/Redis 配置文件说明" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/maoge-blog/2018/02/05/花神(maoge)/3.缓存-中间件/Redis 配置文件说明/" class="article-date">
      <time datetime="2018-02-04T18:03:22.000Z" itemprop="datePublished">2018-02-05</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/maoge-blog/2018/02/05/花神(maoge)/3.缓存-中间件/Redis 配置文件说明/">Redis集群搭建-配置文件</a>
    </h1>
  

      </header>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="Redis集群搭建"><a href="#Redis集群搭建" class="headerlink" title="Redis集群搭建"></a>Redis集群搭建</h3><p>序言</p>
<h4 id="Redis简介"><a href="#Redis简介" class="headerlink" title="Redis简介"></a>Redis简介</h4><ul>
<li>官网给的定义大概意思是：Redis是一个开源，内存数据结构存储，用作数据库，缓存和消息代理。它支持的数据结构有：字符串，哈希，列表，集合，有序集合，位图，超级日志和具有半径查询的地理空间索引。Redis是一个高性能的支持主从同步的key-value数据库。</li>
</ul>
<p>缓存–中间件</p>
<ul>
<li>Redis 配置文件</li>
</ul>
<h1 id="Redis-配置文件"><a href="#Redis-配置文件" class="headerlink" title="Redis 配置文件"></a>Redis 配置文件</h1><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br></pre></td><td class="code"><pre><span class="line"># 当配置中需要配置内存大小时，可以使用 1k, 5GB, 4M 等类似的格式，其转换方式如下(不区分大小写)</span><br><span class="line">#</span><br><span class="line"># 1k =&gt;</span><br><span class="line">1000 bytes</span><br><span class="line"># 1kb =&gt; 1024 bytes</span><br><span class="line"># 1m =&gt; 1000000 bytes</span><br><span class="line"># 1mb =&gt;</span><br><span class="line">1024*1024 bytes</span><br><span class="line"># 1g =&gt; 1000000000 bytes</span><br><span class="line"># 1gb =&gt; 1024*1024*1024</span><br><span class="line">bytes</span><br><span class="line">#</span><br><span class="line"># 内存配置大小写是一样的.比如 1gb 1Gb 1GB 1gB</span><br><span class="line"></span><br><span class="line"># daemonize no 默认情况下，redis不是在后台运行的，如果需要在后台运行，把该项的值更改为yes</span><br><span class="line">daemonize</span><br><span class="line">yes</span><br><span class="line"></span><br><span class="line"># 当redis在后台运行的时候，Redis默认会把pid文件放在/var/run/redis.pid，你可以配置到其他地址。</span><br><span class="line">#</span><br><span class="line">当运行多个redis服务时，需要指定不同的pid文件和端口</span><br><span class="line">pidfile /var/run/redis.pid</span><br><span class="line"></span><br><span class="line"># 指定redis运行的端口，默认是6379</span><br><span class="line">port 6379</span><br><span class="line"></span><br><span class="line"># 指定redis只接收来自于该IP地址的请求，如果不进行设置，那么将处理所有请求，</span><br><span class="line"># 在生产环境中最好设置该项</span><br><span class="line"># bind</span><br><span class="line"><span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line"></span><br><span class="line"># Specify the path for the unix socket that will be used to listen for</span><br><span class="line">#</span><br><span class="line">incoming connections. There is no default, so Redis will not listen</span><br><span class="line"># on a</span><br><span class="line">unix socket when not specified.</span><br><span class="line">#</span><br><span class="line"># unixsocket /tmp/redis.sock</span><br><span class="line">#</span><br><span class="line">unixsocketperm 755</span><br><span class="line"></span><br><span class="line"># 设置客户端连接时的超时时间，单位为秒。当客户端在这段时间内没有发出任何指令，那么关闭该连接</span><br><span class="line"># 0是关闭此设置</span><br><span class="line">timeout</span><br><span class="line"><span class="number">0</span></span><br><span class="line"></span><br><span class="line"># 指定日志记录级别</span><br><span class="line"># Redis总共支持四个级别：debug、verbose、notice、warning，默认为verbose</span><br><span class="line">#</span><br><span class="line">debug  记录很多信息，用于开发和测试</span><br><span class="line"># varbose 有用的信息，不像debug会记录那么多</span><br><span class="line">#</span><br><span class="line">notice 普通的verbose，常用于生产环境</span><br><span class="line"># warning 只有非常重要或者严重的信息会记录到日志</span><br><span class="line">loglevel</span><br><span class="line">debug</span><br><span class="line"></span><br><span class="line"># 配置log文件地址</span><br><span class="line"># 默认值为stdout，标准输出，若后台模式会输出到/dev/null</span><br><span class="line">#logfile</span><br><span class="line">stdout</span><br><span class="line">logfile /var/log/redis/redis.log</span><br><span class="line"></span><br><span class="line"># To enable logging to the system logger, just set 'syslog-enabled' to</span><br><span class="line">yes,</span><br><span class="line"># and optionally update the other syslog parameters to suit your</span><br><span class="line">needs.</span><br><span class="line"># syslog-enabled no</span><br><span class="line"></span><br><span class="line"># Specify the syslog identity.</span><br><span class="line"># syslog-ident redis</span><br><span class="line"></span><br><span class="line"># Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.</span><br><span class="line">#</span><br><span class="line">syslog-facility local0</span><br><span class="line"></span><br><span class="line"># 可用数据库数</span><br><span class="line"># 默认值为16，默认数据库为0，数据库范围在0-（database-1）之间</span><br><span class="line">databases 16</span><br><span class="line"></span><br><span class="line">################################ 快照  </span><br><span class="line">#################################</span><br><span class="line">#</span><br><span class="line"># 保存数据到磁盘，格式如下:</span><br><span class="line">#</span><br><span class="line">#   save</span><br><span class="line">&lt;seconds&gt; &lt;changes&gt;</span><br><span class="line">#</span><br><span class="line">#   </span><br><span class="line">指出在多长时间内，有多少次更新操作，就将数据同步到数据文件rdb。</span><br><span class="line">#   相当于条件触发抓取快照，这个可以多个条件配合</span><br><span class="line">#   </span><br><span class="line">#   </span><br><span class="line">比如默认配置文件中的设置，就设置了三个条件</span><br><span class="line">#</span><br><span class="line">#   save 900 1  900秒内至少有1个key被改变</span><br><span class="line">#   save 300</span><br><span class="line">10  300秒内至少有300个key被改变</span><br><span class="line">#   save 60 10000  60秒内至少有10000个key被改变</span><br><span class="line"></span><br><span class="line">save 900 1</span><br><span class="line">save 300 10</span><br><span class="line">save 60 10000</span><br><span class="line"></span><br><span class="line"># 存储至本地数据库时（持久化到rdb文件）是否压缩数据，默认为yes</span><br><span class="line">rdbcompression yes</span><br><span class="line"></span><br><span class="line"># 本地持久化数据库文件名，默认值为dump.rdb</span><br><span class="line">dbfilename dump.rdb</span><br><span class="line"></span><br><span class="line"># 工作目录</span><br><span class="line">#</span><br><span class="line"># 数据库镜像备份的文件放置的路径。</span><br><span class="line">#</span><br><span class="line">这里的路径跟文件名要分开配置是因为redis在进行备份时，先会将当前数据库的状态写入到一个临时文件中，等备份完成时，</span><br><span class="line">#</span><br><span class="line">再把该该临时文件替换为上面所指定的文件，而这里的临时文件和上面所配置的备份文件都会放在这个指定的路径当中。</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">AOF文件也会存放在这个目录下面</span><br><span class="line">#</span><br><span class="line"># 注意这里必须制定一个目录而不是文件</span><br><span class="line">dir ./</span><br><span class="line"></span><br><span class="line">################################# 复制</span><br><span class="line">#################################</span><br><span class="line"></span><br><span class="line"># 主从复制. 设置该数据库为其他数据库的从数据库.</span><br><span class="line">#</span><br><span class="line">设置当本机为slav服务时，设置master服务的IP地址及端口，在Redis启动时，它会自动从master进行数据同步</span><br><span class="line">#</span><br><span class="line"># slaveof</span><br><span class="line">&lt;masterip&gt; &lt;masterport&gt;</span><br><span class="line"></span><br><span class="line"># 当master服务设置了密码保护时(用requirepass制定的密码)</span><br><span class="line"># slav服务连接master的密码</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">masterauth &lt;master-password&gt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 当从库同主机失去连接或者复制正在进行，从机库有两种运行方式：</span><br><span class="line">#</span><br><span class="line"># 1)</span><br><span class="line">如果slave-serve-stale-data设置为yes(默认设置)，从库会继续相应客户端的请求</span><br><span class="line">#</span><br><span class="line"># 2)</span><br><span class="line">如果slave-serve-stale-data是指为no，出去INFO和SLAVOF命令之外的任何请求都会返回一个</span><br><span class="line">#    错误"SYNC with</span><br><span class="line">master in progress"</span><br><span class="line">#</span><br><span class="line">slave-serve-stale-data yes</span><br><span class="line"></span><br><span class="line"># 从库会按照一个时间间隔向主库发送PINGs.可以通过repl-ping-slave-period设置这个时间间隔，默认是10秒</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">repl-ping-slave-period 10</span><br><span class="line"></span><br><span class="line"># repl-timeout 设置主库批量数据传输时间或者ping回复时间间隔，默认值是60秒</span><br><span class="line">#</span><br><span class="line">一定要确保repl-timeout大于repl-ping-slave-period</span><br><span class="line"># repl-timeout 60</span><br><span class="line"></span><br><span class="line">################################## 安全</span><br><span class="line">###################################</span><br><span class="line"></span><br><span class="line"># 设置客户端连接后进行任何其他指定前需要使用的密码。</span><br><span class="line">#</span><br><span class="line">警告：因为redis速度相当快，所以在一台比较好的服务器下，一个外部的用户可以在一秒钟进行150K次的密码尝试，这意味着你需要指定非常非常强大的密码来防止暴力破解</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">requirepass foobared</span><br><span class="line"></span><br><span class="line"># 命令重命名.</span><br><span class="line">#</span><br><span class="line"># 在一个共享环境下可以重命名相对危险的命令。比如把CONFIG重名为一个不容易猜测的字符。</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">举例:</span><br><span class="line">#</span><br><span class="line"># rename-command CONFIG</span><br><span class="line">b840fc02d524045429941cc15f59e41cb7be6c52</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">如果想删除一个命令，直接把它重命名为一个空字符""即可，如下：</span><br><span class="line">#</span><br><span class="line"># rename-command CONFIG ""</span><br><span class="line"></span><br><span class="line">################################### 约束</span><br><span class="line">####################################</span><br><span class="line"></span><br><span class="line"># 设置同一时间最大客户端连接数，默认无限制，Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数，</span><br><span class="line"># 如果设置</span><br><span class="line">maxclients 0，表示不作限制。</span><br><span class="line"># 当客户端连接数到达限制时，Redis会关闭新的连接并向客户端返回max number of clients</span><br><span class="line">reached错误信息</span><br><span class="line">#</span><br><span class="line"># maxclients 128</span><br><span class="line"></span><br><span class="line"># 指定Redis最大内存限制，Redis在启动时会把数据加载到内存中，达到最大内存后，Redis会先尝试清除已到期或即将到期的Key</span><br><span class="line">#</span><br><span class="line">Redis同时也会移除空的list对象</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">当此方法处理后，仍然到达最大内存设置，将无法再进行写入操作，但仍然可以进行读取操作</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">注意：Redis新的vm机制，会把Key存放内存，Value会存放在swap区</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">maxmemory的设置比较适合于把redis当作于类似memcached的缓存来使用，而不适合当做一个真实的DB。</span><br><span class="line">#</span><br><span class="line">当把Redis当做一个真实的数据库使用的时候，内存使用将是一个很大的开销</span><br><span class="line"># maxmemory &lt;bytes&gt;</span><br><span class="line"></span><br><span class="line"># 当内存达到最大值的时候Redis会选择删除哪些数据？有五种方式可供选择</span><br><span class="line">#</span><br><span class="line"># volatile-lru -&gt;</span><br><span class="line">利用LRU算法移除设置过过期时间的key (LRU:最近使用 Least Recently Used )</span><br><span class="line"># allkeys-lru -&gt;</span><br><span class="line">利用LRU算法移除任何key</span><br><span class="line"># volatile-random -&gt; 移除设置过过期时间的随机key</span><br><span class="line">#</span><br><span class="line">allkeys-&gt;random -&gt; remove a random key, any key</span><br><span class="line"># volatile-ttl -&gt;</span><br><span class="line">移除即将过期的key(minor TTL)</span><br><span class="line"># noeviction -&gt; 不移除任何可以，只是返回一个写错误</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">注意：对于上面的策略，如果没有合适的key可以移除，当写的时候Redis会返回一个错误</span><br><span class="line">#</span><br><span class="line">#       写命令包括: set setnx</span><br><span class="line">setex append</span><br><span class="line">#       incr decr rpush lpush rpushx lpushx linsert lset</span><br><span class="line">rpoplpush sadd</span><br><span class="line">#       sinter sinterstore sunion sunionstore sdiff sdiffstore</span><br><span class="line">zadd zincrby</span><br><span class="line">#       zunionstore zinterstore hset hsetnx hmset hincrby incrby</span><br><span class="line">decrby</span><br><span class="line">#       getset mset msetnx exec sort</span><br><span class="line">#</span><br><span class="line"># 默认是:</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">maxmemory-policy volatile-lru</span><br><span class="line"></span><br><span class="line"># LRU 和 minimal TTL 算法都不是精准的算法，但是相对精确的算法(为了节省内存)，随意你可以选择样本大小进行检测。</span><br><span class="line">#</span><br><span class="line">Redis默认的灰选择3个样本进行检测，你可以通过maxmemory-samples进行设置</span><br><span class="line">#</span><br><span class="line"># maxmemory-samples</span><br><span class="line"><span class="number">3</span></span><br><span class="line"></span><br><span class="line">############################## AOF ###############################</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#</span><br><span class="line">默认情况下，redis会在后台异步的把数据库镜像备份到磁盘，但是该备份是非常耗时的，而且备份也不能很频繁，如果发生诸如拉闸限电、拔插头等状况，那么将造成比较大范围的数据丢失。</span><br><span class="line">#</span><br><span class="line">所以redis提供了另外一种更加高效的数据库备份及灾难恢复方式。</span><br><span class="line"># 开启append</span><br><span class="line">only模式之后，redis会把所接收到的每一次写操作请求都追加到appendonly.aof文件中，当redis重新启动时，会从该文件恢复出之前的状态。</span><br><span class="line">#</span><br><span class="line">但是这样会造成appendonly.aof文件过大，所以redis还支持了BGREWRITEAOF指令，对appendonly.aof 进行重新整理。</span><br><span class="line">#</span><br><span class="line">你可以同时开启asynchronous dumps 和 AOF</span><br><span class="line"></span><br><span class="line">appendonly no</span><br><span class="line"></span><br><span class="line"># AOF文件名称 (默认: "appendonly.aof")</span><br><span class="line"># appendfilename appendonly.aof</span><br><span class="line"></span><br><span class="line"># Redis支持三种同步AOF文件的策略:</span><br><span class="line">#</span><br><span class="line"># no: 不进行同步，系统去操作 . Faster.</span><br><span class="line"># always:</span><br><span class="line">always表示每次有写操作都进行同步. Slow, Safest.</span><br><span class="line"># everysec: 表示对写操作进行累积，每秒同步一次.</span><br><span class="line">Compromise.</span><br><span class="line">#</span><br><span class="line"># 默认是"everysec"，按照速度和安全折中这是最好的。</span><br><span class="line">#</span><br><span class="line">如果想让Redis能更高效的运行，你也可以设置为"no"，让操作系统决定什么时候去执行</span><br><span class="line">#</span><br><span class="line">或者相反想让数据更安全你也可以设置为"always"</span><br><span class="line">#</span><br><span class="line"># 如果不确定就用 "everysec".</span><br><span class="line"></span><br><span class="line"># appendfsync always</span><br><span class="line">appendfsync everysec</span><br><span class="line"># appendfsync no</span><br><span class="line"></span><br><span class="line"># AOF策略设置为always或者everysec时，后台处理进程(后台保存或者AOF日志重写)会执行大量的I/O操作</span><br><span class="line">#</span><br><span class="line">在某些Linux配置中会阻止过长的fsync()请求。注意现在没有任何修复，即使fsync在另外一个线程进行处理</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">为了减缓这个问题，可以设置下面这个参数no-appendfsync-on-rewrite</span><br><span class="line">#</span><br><span class="line"># This means that while</span><br><span class="line">another child is saving the durability of Redis is</span><br><span class="line"># the same as "appendfsync</span><br><span class="line">none", that in pratical terms means that it is</span><br><span class="line"># possible to lost up to 30</span><br><span class="line">seconds of log in the worst scenario (with the</span><br><span class="line"># default Linux</span><br><span class="line">settings).</span><br><span class="line">#</span><br><span class="line"># If you have latency problems turn this to "yes". Otherwise</span><br><span class="line">leave it as</span><br><span class="line"># "no" that is the safest pick from the point of view of</span><br><span class="line">durability.</span><br><span class="line">no-appendfsync-on-rewrite no</span><br><span class="line"></span><br><span class="line"># Automatic rewrite of the append only file.</span><br><span class="line"># AOF 自动重写</span><br><span class="line">#</span><br><span class="line">当AOF文件增长到一定大小的时候Redis能够调用 BGREWRITEAOF 对日志文件进行重写</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">它是这样工作的：Redis会记住上次进行些日志后文件的大小(如果从开机以来还没进行过重写，那日子大小在开机的时候确定)</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">基础大小会同现在的大小进行比较。如果现在的大小比基础大小大制定的百分比，重写功能将启动</span><br><span class="line">#</span><br><span class="line">同时需要指定一个最小大小用于AOF重写，这个用于阻止即使文件很小但是增长幅度很大也去重写AOF文件的情况</span><br><span class="line"># 设置 percentage</span><br><span class="line">为0就关闭这个特性</span><br><span class="line"></span><br><span class="line">auto-aof-rewrite-percentage 100</span><br><span class="line">auto-aof-rewrite-min-size 64mb</span><br><span class="line"></span><br><span class="line">################################## SLOW LOG</span><br><span class="line">###################################</span><br><span class="line"></span><br><span class="line"># Redis Slow Log 记录超过特定执行时间的命令。执行时间不包括I/O计算比如连接客户端，返回结果等，只是命令执行时间</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">可以通过两个参数设置slow log：一个是告诉Redis执行超过多少时间被记录的参数slowlog-log-slower-than(微妙)，</span><br><span class="line">#</span><br><span class="line">另一个是slow log 的长度。当一个新命令被记录的时候最早的命令将被从队列中移除</span><br><span class="line"></span><br><span class="line"># 下面的时间以微妙微单位，因此1000000代表一分钟。</span><br><span class="line">#</span><br><span class="line">注意制定一个负数将关闭慢日志，而设置为0将强制每个命令都会记录</span><br><span class="line">slowlog-log-slower-than 10000</span><br><span class="line"></span><br><span class="line"># 对日志长度没有限制，只是要注意它会消耗内存</span><br><span class="line"># 可以通过 SLOWLOG RESET</span><br><span class="line">回收被慢日志消耗的内存</span><br><span class="line">slowlog-max-len 1024</span><br><span class="line"></span><br><span class="line">################################ VM ###############################</span><br><span class="line"></span><br><span class="line">### WARNING! Virtual Memory is deprecated in Redis 2.4</span><br><span class="line">### The use of</span><br><span class="line">Virtual Memory is strongly discouraged.</span><br><span class="line"></span><br><span class="line"># Virtual Memory allows Redis to work with datasets bigger than the</span><br><span class="line">actual</span><br><span class="line"># amount of RAM needed to hold the whole dataset in memory.</span><br><span class="line"># In</span><br><span class="line">order to do so very used keys are taken in memory while the other keys</span><br><span class="line"># are</span><br><span class="line">swapped into a swap file, similarly to what operating systems do</span><br><span class="line"># with</span><br><span class="line">memory pages.</span><br><span class="line">#</span><br><span class="line"># To enable VM just set 'vm-enabled' to yes, and set the</span><br><span class="line">following three</span><br><span class="line"># VM parameters accordingly to your needs.</span><br><span class="line"></span><br><span class="line">vm-enabled no</span><br><span class="line"># vm-enabled yes</span><br><span class="line"></span><br><span class="line"># This is the path of the Redis swap file. As you can guess, swap</span><br><span class="line">files</span><br><span class="line"># can't be shared by different Redis instances, so make sure to use a</span><br><span class="line">swap</span><br><span class="line"># file for every redis process you are running. Redis will complain if</span><br><span class="line">the</span><br><span class="line"># swap file is already in use.</span><br><span class="line">#</span><br><span class="line"># The best kind of storage for the</span><br><span class="line">Redis swap file (that's accessed at random)</span><br><span class="line"># is a Solid State Disk</span><br><span class="line">(SSD).</span><br><span class="line">#</span><br><span class="line"># *** WARNING *** if you are using a shared hosting the default</span><br><span class="line">of putting</span><br><span class="line"># the swap file under /tmp is not secure. Create a dir with access</span><br><span class="line">granted</span><br><span class="line"># only to Redis user and configure Redis to create the swap file</span><br><span class="line">there.</span><br><span class="line">vm-swap-file /tmp/redis.swap</span><br><span class="line"></span><br><span class="line"># vm-max-memory configures the VM to use at max the specified amount</span><br><span class="line">of</span><br><span class="line"># RAM. Everything that deos not fit will be swapped on disk *if* possible,</span><br><span class="line">that</span><br><span class="line"># is, if there is still enough contiguous space in the swap</span><br><span class="line">file.</span><br><span class="line">#</span><br><span class="line"># With vm-max-memory 0 the system will swap everything it can. Not</span><br><span class="line">a good</span><br><span class="line"># default, just specify the max amount of RAM you can in bytes, but</span><br><span class="line">it's</span><br><span class="line"># better to leave some margin. For instance specify an amount of</span><br><span class="line">RAM</span><br><span class="line"># that's more or less between 60 and 80% of your free</span><br><span class="line">RAM.</span><br><span class="line">vm-max-memory 0</span><br><span class="line"></span><br><span class="line"># Redis swap files is split into pages. An object can be saved using</span><br><span class="line">multiple</span><br><span class="line"># contiguous pages, but pages can't be shared between different</span><br><span class="line">objects.</span><br><span class="line"># So if your page is too big, small objects swapped out on disk will</span><br><span class="line">waste</span><br><span class="line"># a lot of space. If you page is too small, there is less space in the</span><br><span class="line">swap</span><br><span class="line"># file (assuming you configured the same number of total swap file</span><br><span class="line">pages).</span><br><span class="line">#</span><br><span class="line"># If you use a lot of small objects, use a page size of 64 or 32</span><br><span class="line">bytes.</span><br><span class="line"># If you use a lot of big objects, use a bigger page size.</span><br><span class="line"># If</span><br><span class="line">unsure, use the default :)</span><br><span class="line">vm-page-size 32</span><br><span class="line"></span><br><span class="line"># Number of total memory pages in the swap file.</span><br><span class="line"># Given that the page</span><br><span class="line">table (a bitmap of free/used pages) is taken in memory,</span><br><span class="line"># every 8 pages on</span><br><span class="line">disk will consume 1 byte of RAM.</span><br><span class="line">#</span><br><span class="line"># The total swap size is vm-page-size *</span><br><span class="line">vm-pages</span><br><span class="line">#</span><br><span class="line"># With the default of 32-bytes memory pages and 134217728 pages</span><br><span class="line">Redis will</span><br><span class="line"># use a 4 GB swap file, that will use 16 MB of RAM for the page</span><br><span class="line">table.</span><br><span class="line">#</span><br><span class="line"># It's better to use the smallest acceptable value for your</span><br><span class="line">application,</span><br><span class="line"># but the default is large in order to work in most</span><br><span class="line">conditions.</span><br><span class="line">vm-pages 134217728</span><br><span class="line"></span><br><span class="line"># Max number of VM I/O threads running at the same time.</span><br><span class="line"># This threads</span><br><span class="line">are used to read/write data from/to swap file, since they</span><br><span class="line"># also encode and</span><br><span class="line">decode objects from disk to memory or the reverse, a bigger</span><br><span class="line"># number of</span><br><span class="line">threads can help with big objects even if they can't help with</span><br><span class="line"># I/O itself</span><br><span class="line">as the physical device may not be able to couple with many</span><br><span class="line"># reads/writes</span><br><span class="line">operations at the same time.</span><br><span class="line">#</span><br><span class="line"># The special value of 0 turn off threaded</span><br><span class="line">I/O and enables the blocking</span><br><span class="line"># Virtual Memory</span><br><span class="line">implementation.</span><br><span class="line">vm-max-threads 4</span><br><span class="line"></span><br><span class="line">############################### ADVANCED CONFIG</span><br><span class="line">###############################</span><br><span class="line"></span><br><span class="line"># 当hash中包含超过指定元素个数并且最大的元素没有超过临界时，</span><br><span class="line">#</span><br><span class="line">hash将以一种特殊的编码方式（大大减少内存使用）来存储，这里可以设置这两个临界值</span><br><span class="line"># Redis</span><br><span class="line">Hash对应Value内部实际就是一个HashMap，实际这里会有2种不同实现，</span><br><span class="line">#</span><br><span class="line">这个Hash的成员比较少时Redis为了节省内存会采用类似一维数组的方式来紧凑存储，而不会采用真正的HashMap结构，对应的value</span><br><span class="line">redisObject的encoding为zipmap,</span><br><span class="line">#</span><br><span class="line">当成员数量增大时会自动转成真正的HashMap,此时encoding为ht。</span><br><span class="line">hash-max-zipmap-entries</span><br><span class="line"><span class="number">512</span></span><br><span class="line">hash-max-zipmap-value 64</span><br><span class="line"></span><br><span class="line"># list数据类型多少节点以下会采用去指针的紧凑存储格式。</span><br><span class="line">#</span><br><span class="line">list数据类型节点值大小小于多少字节会采用紧凑存储格式。</span><br><span class="line">list-max-ziplist-entries</span><br><span class="line"><span class="number">512</span></span><br><span class="line">list-max-ziplist-value 64</span><br><span class="line"></span><br><span class="line"># set数据类型内部数据如果全部是数值型，且包含多少节点以下会采用紧凑格式存储。</span><br><span class="line">set-max-intset-entries</span><br><span class="line"><span class="number">512</span></span><br><span class="line"></span><br><span class="line"># zsort数据类型多少节点以下会采用去指针的紧凑存储格式。</span><br><span class="line">#</span><br><span class="line">zsort数据类型节点值大小小于多少字节会采用紧凑存储格式。</span><br><span class="line">zset-max-ziplist-entries</span><br><span class="line"><span class="number">128</span></span><br><span class="line">zset-max-ziplist-value 64</span><br><span class="line"></span><br><span class="line"># Redis将在每100毫秒时使用1毫秒的CPU时间来对redis的hash表进行重新hash，可以降低内存的使用</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">当你的使用场景中，有非常严格的实时性需要，不能够接受Redis时不时的对请求有2毫秒的延迟的话，把这项配置为no。</span><br><span class="line">#</span><br><span class="line">#</span><br><span class="line">如果没有这么严格的实时性要求，可以设置为yes，以便能够尽可能快的释放内存</span><br><span class="line">activerehashing yes</span><br><span class="line"></span><br><span class="line">################################## INCLUDES</span><br><span class="line">###################################</span><br><span class="line"></span><br><span class="line"># 指定包含其它的配置文件，可以在同一主机上多个Redis实例之间使用同一份配置文件，而同时各个实例又拥有自己的特定配置文件</span><br><span class="line">#</span><br><span class="line">include /path/to/local.conf</span><br><span class="line"># include /path/to/other.conf</span><br></pre></td></tr></table></figure>

      
    </div>
    
    <div class="article-info article-info-index">
      
      
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/maoge-blog/categories/缓存-中间件/">缓存-中间件</a>
    </div>


      
      
      <div class="clearfix"></div>
    </div>
    
  </div>
  
</article>









  
    <article id="post-花神(maoge)/3.缓存-中间件/Redis----集群搭建" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/maoge-blog/2018/02/05/花神(maoge)/3.缓存-中间件/Redis----集群搭建/" class="article-date">
      <time datetime="2018-02-04T18:03:22.000Z" itemprop="datePublished">2018-02-05</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/maoge-blog/2018/02/05/花神(maoge)/3.缓存-中间件/Redis----集群搭建/">Redis集群搭建-实践</a>
    </h1>
  

      </header>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="Redis集群搭建-实践"><a href="#Redis集群搭建-实践" class="headerlink" title="Redis集群搭建-实践"></a>Redis集群搭建-实践</h3><p>序言<br>Redis简介</p>
<ul>
<li style="list-style: none"><input type="checkbox"> 官网给的定义大概意思是：Redis是一个开源，内存数据结构存储，用作数据库，缓存和消息代理。它支持的数据结构有：字符串，哈希，列表，集合，有序集合，位图，超级日志和具有半径查询的地理空间索引。Redis是一个高性能的支持主从同步的key-value数据库。</li>
</ul>
<hr>
<p>缓存–中间件</p>
<ul>
<li>Redis三主三从集群搭建</li>
</ul>
<hr>

      
    </div>
    
    <div class="article-info article-info-index">
      
      
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/maoge-blog/categories/缓存-中间件/">缓存-中间件</a>
    </div>


      
      
      <div class="clearfix"></div>
    </div>
    
  </div>
  
</article>









  
  
    <nav id="page-nav">
      <a class="extend prev" rel="prev" href="/maoge-blog/page/6/">&laquo; Prev</a><a class="page-number" href="/maoge-blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/maoge-blog/page/5/">5</a><a class="page-number" href="/maoge-blog/page/6/">6</a><span class="page-number current">7</span>
    </nav>
  
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2016-2018 zhengweiMao
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/maoge-blog/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>